package com.smart.platform.common;


import com.smart.platform.utils.AliOSSUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.File;
import java.io.IOException;
import java.util.Base64;

/**
 * Base64编码转图片.(并保存)
 */
@Slf4j
public class Base64utils {
    @Autowired
    private static AliOSSUtils aliOSSUtils;
    //imgPath为转换为图片后，图片的保存路径


    public static void base64ToImg(String base64, String imgPath) {
        byte[] bytes = Base64.getDecoder().decode(base64);

        try {
            FileUtils.writeByteArrayToFile(new File(imgPath), bytes);
            log.info("Base64转图片成功{}", imgPath);
        } catch (IOException e) {
            e.printStackTrace();
            log.info("{}转图片失败,error:", imgPath, e);
        }
    }
}
